#include "resource.h"

#include <QPixmap>
#include <QDebug>
#include <QDir>

Resource *Resource::resource = 0;

Resource *Resource::getInstance()
{
    if (!resource) {
        resource = new Resource();
    }
    return resource;
}

Resource::Resource()
{
    init();
}

void Resource::init()
{
    qDebug() << QDir().currentPath();

    initWelcome();

    initMainMenu();

    initAreaSelectionMenu_1();

    initMiniMenu();

    initSongMenu();
//  Tips
    tipList << "../VisualSoft_resource/image/ktv/tip/1.png"
            << "../VisualSoft_resource/image/ktv/tip/2.png"
            << "../VisualSoft_resource/image/ktv/tip/3.png"
            << "../VisualSoft_resource/image/ktv/tip/4.png"
            << "../VisualSoft_resource/image/ktv/tip/5.png"
            << "../VisualSoft_resource/image/ktv/tip/6.png";
//  List
    backgroundPixmap_singerList = new QPixmap("../VisualSoft_resource/image/ktv/background_singerList.jpg");
    backgroundPixmap_songList = new QPixmap("../VisualSoft_resource/image/ktv/background_songList.jpg");
    backgroundPixmap_selectedSongList = new QPixmap("../VisualSoft_resource/image/ktv/background_selectedSongList.jpg");
    backgroundPixmap_singer = new QPixmap("../VisualSoft_resource/image/ktv/background_singer.png");
    backgroundPixmap_song = new QPixmap("../VisualSoft_resource/image/ktv/background_song.jpg");
    backgroundPixmap_selectedSong = new QPixmap("../VisualSoft_resource/image/ktv/background_selectedSong.png");
    null_pixmap = new QPixmap("../VisualSoft_resource/image/ktv/null_pixmap.png");
//  Keyboard
    frame = new QPixmap("../VisualSoft_resource/image/ktv/keyboard/frame.png");
    doubleFrame = new QPixmap("../VisualSoft_resource/image/ktv/keyboard/double_frame.png");
    keyboard = new QPixmap("../VisualSoft_resource/image/ktv/keyboard/keyboard.png");
    input_field_background = new QPixmap("../VisualSoft_resource/image/ktv/keyboard/input_field_background.png");
}

void Resource::initWelcome()
{
    welcome = new QList<QPixmap *>;
    welcomePath = "../VisualSoft_resource/image/ktv/welcome/";
    welcomePrefix = "";
    welcomeSuffix = ".jpg";
    welcomeCount = 63;
    welcomeTime = 9000;
}

void Resource::initMainMenu()
{
    mainmenu_appearance = new QList<QPixmap *>;
    mainmenu_appearance_path = "../VisualSoft_resource/image/ktv/menu/mainmenu/appearance/";
    mainmenu_appearance_prefix = "";
    mainmenu_appearance_suffix = ".jpg";
    mainmenu_appearance_count = 7;
    mainmenu_appearance_time = 2000;
    mainmenu_focus = new QList<QPixmap *>;
    mainmenu_focus_path = "../VisualSoft_resource/image/ktv/menu/mainmenu/focus/";
    mainmenu_focus_prefix = "";
    mainmenu_focus_suffix = ".jpg";
    mainmenu_focus_count = 6;
    mainmenu_focus_time = 2000;
    mainmenu_focus_alpha = new QList<QPixmap *>;
    mainmenu_focus_alpha_path = "../VisualSoft_resource/image/ktv/menu/mainmenu/focus_alpha/";
    mainmenu_focus_alpha_prefix = "";
    mainmenu_focus_alpha_suffix = ".jpg";
    mainmenu_focus_alpha_count = 6;
    mainmenu_focus_alpha_time = 2000;
    mainmenu_focus_area = new QList<QPixmap *>;
    mainmenu_focus_area_path = "../VisualSoft_resource/image/ktv/menu/mainmenu/focus_area/";
    mainmenu_focus_area_prefix = "";
    mainmenu_focus_area_suffix = ".jpg";
    mainmenu_focus_area_count = 6;
    mainmenu_focus_area_time = 2000;
    mainmenu_focus_quit = new QList<QPixmap *>;
    mainmenu_focus_quit_path = "../VisualSoft_resource/image/ktv/menu/mainmenu/focus_quit/";
    mainmenu_focus_quit_prefix = "";
    mainmenu_focus_quit_suffix = ".jpg";
    mainmenu_focus_quit_count = 6;
    mainmenu_focus_quit_time = 2000;
}

void Resource::initAreaSelectionMenu_1()
{
    area_background = new QPixmap("../VisualSoft_resource/image/ktv/menu/areaselectionmenu/inland_ht/0.jpg");
    areaselectionmenu_inland_ht = new QList<QPixmap *>;
    area_inland_ht_path = "../VisualSoft_resource/image/ktv/menu/areaselectionmenu/inland_ht/";
    area_inland_ht_prefix = "";
    area_inland_ht_suffix = ".jpg";
    area_inland_ht_count = 20;
    area_inland_ht_time = 3000;
    areaselectionmenu_ht_ea = new QList<QPixmap *>;
    area_ht_ea_path = "../VisualSoft_resource/image/ktv/menu/areaselectionmenu/ht_ea/";
    area_ht_ea_prefix = "";
    area_ht_ea_suffix = ".jpg";
    area_ht_ea_count = 31;
    area_ht_ea_time = 3000;
    areaselectionmenu_ea_inland = new QList<QPixmap *>;
    area_ea_inland_path = "../VisualSoft_resource/image/ktv/menu/areaselectionmenu/ea_inland/";
    area_ea_inland_prefix = "";
    area_ea_inland_suffix = ".jpg";
    area_ea_inland_count = 30;
    area_ea_inland_time = 3000;

    areaselectionmenu_inland_ea = new QList<QPixmap *>;
    area_inland_ea_path = "../VisualSoft_resource/image/ktv/menu/areaselectionmenu/inland_ea/";
    areaselectionmenu_ea_ht = new QList<QPixmap *>;
    area_ea_ht_path = "../VisualSoft_resource/image/ktv/menu/areaselectionmenu/ea_ht/";
    areaselectionmenu_ht_inland = new QList<QPixmap *>;
    area_ht_inland_path = "../VisualSoft_resource/image/ktv/menu/areaselectionmenu/ht_inland/";
}

void Resource::initAreaSelectionMenu_2()
{
    QListIterator<QPixmap *> it1(*areaselectionmenu_inland_ht);
    it1.toBack();
    while (it1.hasPrevious()) {
        areaselectionmenu_ht_inland->append(it1.previous());
    }

    QListIterator<QPixmap *> it2(*areaselectionmenu_ht_ea);
    it2.toBack();
    while (it2.hasPrevious()) {
        areaselectionmenu_ea_ht->append(it2.previous());
    }

    QListIterator<QPixmap *> it3(*areaselectionmenu_ea_inland);
    it3.toBack();
    while (it3.hasPrevious()) {
        areaselectionmenu_inland_ea->append(it3.previous());
    }
}

void Resource::initMiniMenu()
{
//  Minimenu
    minimenu_appearance_singer = new QList<QPixmap *>;
    minimenu_appearance_song = new QList<QPixmap *>;
    minimenu_appearance_selectedSong = new QList<QPixmap *>;
    minimenu_option_singer = new QList<QPixmap *>;
    minimenu_option_song = new QList<QPixmap *>;
    minimenu_option_selectedSong = new QList<QPixmap *>;
    for (int i = 0; i < 8; i++) {
        QString pre = "../VisualSoft_resource/image/ktv/menu/minimenu/appearance/singer/";
        QString post = ".png";
        QString fileName = pre.append(QString::number(i)).append(post);
        qDebug() << fileName;
        minimenu_appearance_singer->append(new QPixmap(fileName));
    }
    for (int i = 0; i < 8; i++) {
        QString pre = "../VisualSoft_resource/image/ktv/menu/minimenu/appearance/song/";
        QString post = ".png";
        QString fileName = pre.append(QString::number(i)).append(post);
        qDebug() << fileName;
        minimenu_appearance_song->append(new QPixmap(fileName));
    }
    for (int i = 0; i < 8; i++) {
        QString pre = "../VisualSoft_resource/image/ktv/menu/minimenu/appearance/selectedSong/";
        QString post = ".png";
        QString fileName = pre.append(QString::number(i)).append(post);
        qDebug() << fileName;
        minimenu_appearance_selectedSong->append(new QPixmap(fileName));
    }
    for (int i = 0; i < 6; i++) {
        QString pre = "../VisualSoft_resource/image/ktv/menu/minimenu/option/singer/";
        QString post = ".png";
        QString fileName = pre.append(QString::number(i)).append(post);
        qDebug() << fileName;
        minimenu_option_singer->append(new QPixmap(fileName));
    }
    for (int i = 0; i < 6; i++) {
        QString pre = "../VisualSoft_resource/image/ktv/menu/minimenu/option/song/";
        QString post = ".png";
        QString fileName = pre.append(QString::number(i)).append(post);
        qDebug() << fileName;
        minimenu_option_song->append(new QPixmap(fileName));
    }
    for (int i = 0; i < 6; i++) {
        QString pre = "../VisualSoft_resource/image/ktv/menu/minimenu/option/selectedSong/";
        QString post = ".png";
        QString fileName = pre.append(QString::number(i)).append(post);
        qDebug() << fileName;
        minimenu_option_selectedSong->append(new QPixmap(fileName));
    }
}

void Resource::initSongMenu()
{
//  SongMenu
    songmenu_appearance = new QList<QPixmap *>;
    songmenu_option = new QList<QPixmap *>;
    for (int i = 0; i < 8; i++) {
        QString pre = "../VisualSoft_resource/image/ktv/menu/songmenu/appearance/";
        QString post = ".png";
        QString fileName = pre.append(QString::number(i)).append(post);
        qDebug() << fileName;
        songmenu_appearance->append(new QPixmap(fileName));
    }
    for (int i = 0; i < 2; i++) {
        QString pre = "../VisualSoft_resource/image/ktv/menu/songmenu/option/";
        QString post = ".png";
        QString fileName = pre.append(QString::number(i)).append(post);
        qDebug() << fileName;
        songmenu_option->append(new QPixmap(fileName));
    }
}

void Resource::releaseWelcome()
{
    qDebug() << "resource: \tbegin release welcome";
	/*
    for (int i = 0; i < welcome->size(); i++) {
        release = welcome->at(i);
        delete release;
    }
//	*/
	qDeleteAll(*welcome);
	welcome->clear();
    qDebug() << "resource: \tfinish release welcome";
    qDebug() << "";
}

void Resource::releaseMainMenu_1()
{
	/*
    qDebug() << "resource: \tbegin release mainmenu appearance";
    for (int i = 0; i < mainmenu_appearance->size(); i++) {
        release = mainmenu_appearance->at(i);
        delete release;
    }
//	*/
	qDeleteAll(*mainmenu_appearance);
	mainmenu_appearance->clear();
    qDebug() << "resource: \tfinish release mainmenu appearance";
    qDebug() << "resource: \tbegin release mainmenu focus";

	/*
    for (int i = 0; i < mainmenu_focus->size(); i++) {
        release = mainmenu_focus->at(i);
        delete release;
    }
//	*/
	qDeleteAll(*mainmenu_focus);
	mainmenu_focus->clear();
    qDebug() << "resource: \tfinish release mainmenu focus";
    qDebug() << "";
}

void Resource::releaseMainMenu_2()
{
    qDebug() << "resource: \tbegin release mainmenu focus area";
	/*
    for (int i = 0; i < mainmenu_focus_alpha->size(); i++) {
        release = mainmenu_focus_alpha->at(i);
        delete release;
    }
//	*/
	qDeleteAll(*mainmenu_focus_alpha);
	mainmenu_focus_alpha->clear();
    qDebug() << "resource: \tfinish release mainmenu focus area";
    qDebug() << "resource: \tbegin release mainmenu focus area";

	/*
    for (int i = 0; i < mainmenu_focus_area->size(); i++) {
        release = mainmenu_focus_area->at(i);
        delete release;
    }
//	*/
	qDeleteAll(*mainmenu_focus_area);
	mainmenu_focus_area->clear();
    qDebug() << "resource: \tfinish release mainmenu focus area";
    qDebug() << "resource: \tbegin release mainmenu focus quit";

	/*
    for (int i = 0; i < mainmenu_focus_quit->size(); i++) {
        release = mainmenu_focus_quit->at(i);
        delete release;
    }
//	*/
	qDeleteAll(*mainmenu_focus_quit);
	mainmenu_focus_quit->clear();
    qDebug() << "resource: \tfinish release mainmenu focus quit";
    qDebug() << "";
}
